<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/displaytag.tld" prefix="display"%>
<%@ page import="java.util.Collection"%>
<%@ page import="java.util.List"%>

<script language="JavaScript" src="<%= request.getContextPath() + "/js/popUP.js" %>"></script>
<script language="JavaScript" src="<%= request.getContextPath() + "/js/calendar6.js" %>"></script>
<link href="<%= request.getContextPath() + "/css/bloques.css" %>" rel="stylesheet" type="text/css">

<script>
  
  // Script para seleccionar todas las opciones del beneficio
  var checkflag = "false";
  function check(tamano) {
    var nom = "";
    if (checkflag == "false") 
    {
      for (i = 0; i < tamano; i++) 
      {
        nom = "atributo"+i;
        document.forms['frmseleccion'].elements[nom].checked = true
      }
      checkflag = "true";
      return "Uncheck All"; 
    }
    else {
      for (i = 0; i < tamano; i++) 
      {
        nom = "atributo"+i;
        document.forms['frmseleccion'].elements[nom].checked = false
      }
      checkflag = "false";
      return "Check All"; 
    }
  }
  // Fin del Script
  
  // Script para seleccionar todas las opciones del beneficiario
  var checkflagbene = "false";
  function checkbene(tamano) {
    var nom = "";
    if (checkflagbene == "false") 
    {
      for (i = 0; i < tamano; i++) 
      {
        nom = "atrbeneficiario"+i;
        document.forms['frmseleccion'].elements[nom].checked = true
      }
      checkflagbene = "true";
      return "Uncheck All"; 
    }
    else {
      for (i = 0; i < tamano; i++) 
      {
        nom = "atrbeneficiario"+i;
        document.forms['frmseleccion'].elements[nom].checked = false
      }
      checkflagbene = "false";
      return "Check All"; 
    }
  }
  // Fin del Script
  
  
  function habilita(){
    if(document.frmseleccion.filter.value == "7")
    {
      document.frmseleccion.valor2.disabled = false; 
    }else
    {
      document.frmseleccion.valor2.disabled = true; 
      document.frmseleccion.valor2.value = "";
    }
  
  }  

 function verificar(){
   
    document.frmseleccion.action = '<%=request.getContextPath()+"/Reportes/Detallados/SelectionFilter.do"%>'
    document.frmseleccion.accion.value ='1';
    document.frmseleccion.target = "_self";
    document.frmseleccion.submit();
  }
  
  function verificarLista(){
    if(document.frmseleccion.filter.value == "7")
    {

      if(document.frmseleccion.descVflex.value == "" || document.frmseleccion.valor2.value == "")
      {
        alert("Por favor ingrese tanto el valor1 como el valor2");
      }else
      {
        document.frmseleccion.action = '<%=request.getContextPath()+"/Reportes/Detallados/SelectionFilter.do"%>'
        document.frmseleccion.accion.value ='2';
        document.frmseleccion.target = "_self";
        document.frmseleccion.submit();
      }
    }else
    {
      if(document.frmseleccion.descVflex.value == "")
      {
        alert("Por favor ingrese un valor");
      }else
      {
        document.frmseleccion.action = '<%=request.getContextPath()+"/Reportes/Detallados/SelectionFilter.do"%>'
        document.frmseleccion.accion.value ='2';
        document.frmseleccion.target = "_self";
        document.frmseleccion.submit();
      }
      
    }
  }
    
  function verificar1(){
    if(document.frmseleccion.filter.value == "7")
    {

      if(document.frmseleccion.valor.value == "" || document.frmseleccion.valor2.value == "")
      {
        alert("Por favor ingrese tanto el valor1 como el valor2");
      }else
      {
        document.frmseleccion.action = '<%=request.getContextPath()+"/Reportes/Detallados/SelectionFilter.do"%>'
        document.frmseleccion.accion.value ='2';
        document.frmseleccion.target = "_self";
        document.frmseleccion.submit();
      }
    }else
    {
      if(document.frmseleccion.valor.value == "")
      {
        alert("Por favor ingrese un valor");
      }else
      {
        document.frmseleccion.action = '<%=request.getContextPath()+"/Reportes/Detallados/SelectionFilter.do"%>'
        document.frmseleccion.accion.value ='2';
        document.frmseleccion.target = "_self";
        document.frmseleccion.submit();
      }
      
    }
  }
  
  function Generar(){
    document.frmseleccion.target = "blank";
    document.frmseleccion.submit();
  }
  
  function regresar(){
   
    document.frmseleccion.action = '<%=request.getContextPath()+"/Reportes/Detallados/ReportDetBeneficiario.do"%>'
    document.frmseleccion.target = "_self";
    document.frmseleccion.submit();
  }
  
  function validarOtros(tamano)
  {
    var nom = "";
    var marcado = false;
    for (i = 0; i < tamano; i++) 
    {
      nom = atrBeneficiarios[i];
      if (document.forms['frmseleccion'].elements[nom].checked) 
      {
        marcado = true;
        break;
      }  
    } 
    if (marcado == false)
    {
      alert('Por favor seleccione al menos un atributo.');
    }else
    {
      document.frmseleccion.target = "blank";
      document.frmseleccion.submit();
    }
  }
  
</script>
<script src="<%=request.getContextPath()%>/js/displaytag.js" type="text/javascript"></script>
<form name="frmseleccion" action="<%=request.getContextPath()+"/Reportes/Detallados/GenerationReportBeneficiario.do"%>" method="get">
 
 <logic:present scope="session" name="errorfecha">
  <BR>
  <strong><DIV align="center" class="titulosenblanco"><%=(String)session.getAttribute("errorfecha")%></DIV></strong>
  <BR>
  
  <div align="center">
  <input type="IMAGE"  src="<%=request.getContextPath()%>/images/b_atras.gif" onclick="regresar()"/>
  </div>
</logic:present> 
 
  <logic:notPresent scope="session" name="errorfecha">
       <p align="center" class="titulosenblanco">Reporte&nbsp;Detallado&nbsp;Beneficiario</p>
       
      
       <table cellspacing="3" cellpadding="2" border="0" width="10%" align="center">
        
        <tr>
          <td align="center" class="celdatabla">Parametro</td>
          <td align="center" class="celdatabla">Filtro</td>
          <td align="center" class="celdatabla">Valor1</td>
          <td align="center" class="celdatabla">Valor2</td>
        </tr>
        <tr>
          <td>
        <%   Object codigoatri = (Object)session.getAttribute("codigo"); 
             if(codigoatri==null) codigoatri = "nulo";
        %>  
            <logic:present name="listabeneficiario">
                  <logic:iterate id="atributos" name="listabeneficiario" length="1" type="com.cs.beneficios.business.model.RepAtributoVO">
                    <div align="center">
                    <html:select onchange="verificar()" name="atributos" property="codigo" title="atributos" styleClass="form" value="<%=(String)codigoatri%>">
                      <option value="nulo">Seleccione un atributo</option>
                      <html:options name="lbeneficiarios" labelName="nombre" labelProperty="etiqueta" property="nombre" collection="lbeneficiarios"/>
                      
                      <logic:present name="listaatributos">
                        <html:options name="listaatributos" labelName="codigo" labelProperty="etiqueta" property="codigo" collection="listaatributos"/>
                      </logic:present>  
                      
                    </html:select>
                    </div>
                  </logic:iterate>
            </logic:present>
          </td>
          <%Object obTipodato = (Object)session.getAttribute("tipodato");
            String strTipoDato="";
            if(obTipodato!=null)
            {
              strTipoDato = (String)session.getAttribute("tipodato");
            }else
            {
              strTipoDato = "T";
            }
            
            if(strTipoDato.equals("A") || strTipoDato.equals("L"))
            {
          %>
              <td align="center">
                  <select name="filter" class="form">
                    <option value="3">IGUAL</option>
                    <option value="4">DIFERENTE</option>
                   
                </select>
                </td>
              
          <%}else{ %>      
                <td align="center">
                <select name="filter" onchange="habilita()" class="form">
                  <option value="1">MAYOR O IGUAL</option>
                  <option value="2">MENOR O IGUAL</option>
                  <option value="3">IGUAL</option>
                  <option value="4">DIFERENTE</option>
                  <option value="5">MENOR</option>
                  <option value="6">MAYOR</option>
                  <option value="7">ENTRE</option>
                </select>
                </td>
         <%    }   %>     
          
          <td align="center">
            <logic:notPresent name="listavfl">
              <%if(!strTipoDato.equals("F"))
              {
            %>
                <input class="form" type="text" name="valor"/>
            <%}else{%>
                 <input readonly="readonly" type="TEXT" class="form" name="valor" size="15"/>
               
               <a href="javascript:effectiveFrom1.popup();">
                  <img src="<%= request.getContextPath() + "/images/cal.gif" %>" width="16" height="16" border="0" alt="Click para seleccionar la fecha">
               </a>
               <script language="javascript">
                 var effectiveFrom1 = new calendar1(document.forms['frmseleccion'].elements['valor'],"-",'<%=request.getContextPath()+"/js/"%>');
                 
               </script>
            <%}%>
           </logic:notPresent>
           <logic:present name="listavfl">
              <logic:iterate id="vfl" name="listavfl" length="1" type="com.cs.beneficios.business.model.VflexVO">
                 <html:select name="vfl" property="descVflex" title="vfl" styleClass="form">
                   <html:options name="listavfl" labelName="valor" labelProperty="descVflex" property="nombreVflex" collection="listavfl"/>
                 </html:select>
              </logic:iterate>
           </logic:present>
          </td>
          <td align="center">
              <%if(!strTipoDato.equals("F"))
          {
        %>
            <input disabled="disabled" class="form" type="text" name="valor2"/>
        <%}else{%>
             <input readonly="readonly" type="TEXT" class="form" name="valor2" size="15"/>
           
           <a href="javascript:effectiveUntil1.popup();">
              <img src="<%= request.getContextPath() + "/images/cal.gif" %>" width="16" height="16" border="0" alt="Click para seleccionar la fecha">
           </a>
           <script language="javascript">
            
             var effectiveUntil1 = new calendar1(document.forms['frmseleccion'].elements['valor2'],"-",'<%=request.getContextPath()+"/js/"%>');
           </script>
        <%}%>
          </td>
          <tr>
          <td align="center" colspan="4">
            <P>&nbsp;</P>
            <P>
              <logic:present name="listavfl">
                <input type="button" value="Agregar Filtro" onclick="verificarLista()"/>
              </logic:present>
              <logic:notPresent name="listavfl">
                <input type="button" value="Agregar Filtro" onclick="verificar1()"/>
              </logic:notPresent>
            </P>
           </td>
          </tr>
        </tr>
      </table>
      
      
      <div align="center">
      <logic:present name="ListaFiltrado">
        <table  cellspacing="3" cellpadding="2" border="0" width="50%" align="center">
          <tr>
          <td>
            <display:table name="sessionScope.ListaFiltrado" id="lfiltro" cellpadding="3" cellspacing="1" style="width:100%" class="bordestable">
                  <display:column headerClass="headerTable" title="Atributo" class="Numero" sortable="true">
                      <div align="center">
                      <bean:write name="lfiltro" property="campo" /> 
                      </div>
                  </display:column>
                  <display:column headerClass="headerTable" title="Filtro" class="Numero" sortable="true">
                      <div align="center">
                      <bean:write name="lfiltro" property="filtro" /> 
                      </div>
                  </display:column>
                  <display:column headerClass="headerTable" title="Valor1" class="Numero" sortable="true">
                      <div align="center">
                      <bean:write name="lfiltro" property="etiquetaValor" /> 
                      </div>
                  </display:column>
                  <display:column headerClass="headerTable" title="Valor2" class="Numero" sortable="true">
                      <div align="center">
                      <bean:write name="lfiltro" property="valor2" /> 
                      </div>
                  </display:column>
                  <display:column headerClass="headerTable" title="Eliminar" class="Numero" sortable="true">
                      <div align="center">
                          <html:link onclick="return confirm('Esta seguro que desea eliminar el filtro?')" paramId="codigos" paramName="lfiltro" paramProperty="codigo" page="/Reportes/Detallados/SelectionFilter.do">
                            <div align="center"><img src="<%= request.getContextPath() + "/images/Delete.gif" %>" width="16" height="16" border="0"></div>
                          </html:link>   
                      </div>
                  </display:column>
             </display:table>     
          </td>
          </tr>
        </table>
      </logic:present>
      <P>________________________________________________________________________</P>
      <P class="titulosenblanco">Seleccione los campos que desea que aparezcan en el reporte</P>
      
      </div>      
      
      <div align="center">
      <%
          Collection atrBeneficios = (Collection)session.getAttribute("listaatributos");
          int ContBeneficios = 0; 
          if (atrBeneficios != null) 
            ContBeneficios = atrBeneficios.size();
          atrBeneficios = null; 
          Collection atrBeneficiarios = (Collection)session.getAttribute("listabeneficiario");
          int ContBeneficiarios = atrBeneficiarios.size()+ContBeneficios;
          atrBeneficiarios = null;
      %>

        <script>
          var atrBeneficiarios = new Array(<%=ContBeneficiarios%>); 
          var tamano = <%=ContBeneficiarios%>;
          var i = 0;
        </script>
      <logic:present name="listaatributos">

        <div align="center>"><P class="titulosenblanco">Atributos del beneficio</P></div>
        <table  cellspacing="3" cellpadding="2" border="0" width="40%" align="center">
        <%
          String nombre = "";
          List lListaAtributos = (List)session.getAttribute("listaatributos");
          int tamano = lListaAtributos.size();
          int j = 0;
        %>
          <tr>
            <td align="right">
              <font class="celdatabla">Seleccionar Todos</font><input type="checkbox" name="SLT_ALL" value="Check All" onClick="this.value=check(<%=tamano%>)"/>  
            </td>
          </tr>
          <tr>
          <td>
             <display:table name="sessionScope.listaatributos" id="beneotot" cellpadding="3" cellspacing="1" style="width:100%" class="bordestable">
                  <display:column headerClass="headerTable" title="Atributo" class="Numero" sortable="true" group="1">
                      <div align="center">
                      <bean:write name="beneotot" property="etiqueta" /> 
                      </div>
                  </display:column>
                  <display:column headerClass="headerTable" title="Escoger" class="Numero" >
                      <div align="center">
                      <bean:define id="codAtr" name="beneotot" property="codigo" />
                      <% nombre = "atributo"+j; %>
                      <input type="checkbox" name="<%=nombre%>" value="<bean:write name="beneotot" property="codigo"/>"/>
                      <%
                        j++;
                      %>
                      <script>
                          atrBeneficiarios[i] = '<%=nombre%>';
                          i++;
                      </script>
                      </div>
                  </display:column>	
             </display:table>     
          </td>
          </tr>
        </table>
      </logic:present>  
        <logic:present name="listabeneficiario">
        <P class="titulosenblanco">Atributos del beneficiario</P>
        

        <table  cellspacing="3" cellpadding="2" border="0" width="40%" align="center">
          <%
            String strnombre = "";
            List lListaBeneficiario = (List)session.getAttribute("listabeneficiario");
            int tamanoBene = lListaBeneficiario.size();
            int k = 0;
          %>
          <tr>
            <td align="right">
              <font class="celdatabla">Seleccionar Todos</font><input type="checkbox" name="SLT_ALL" value="Check All" onClick="this.value=checkbene(<%=tamanoBene%>)"/>  
            </td>
          </tr>
          <tr>
          <td>
             <display:table name="sessionScope.listabeneficiario" id="beneficiario" cellpadding="3" cellspacing="1" style="width:100%" class="bordestable">
                 <display:column headerClass="headerTable" title="Atributo" class="Numero" sortable="true" group="1">
                    <div align="center">
                    <bean:write name="beneficiario" property="etiqueta" /> 
                    </div>
                 </display:column>
                 <display:column headerClass="headerTable" title="Escoger" class="Numero" >
                    <div align="center">
                    <%
                      strnombre = "atrbeneficiario"+k;
                    %>
                    <input type="checkbox" name="<%=strnombre%>" value="<bean:write name="beneficiario" property="nombre"/>"/>
                    <%
                      k++;
                    %>
                    </div>
                    <script>
                        atrBeneficiarios[i] = '<%=strnombre%>';
                        i++;
                    </script>
                    
                 </display:column>	
             </display:table>  
          </td>
          </tr>
        </table>
        </logic:present>
        <input type="HIDDEN" name="accion">

      <P>
        <input type="button" value="Generar" onclick="validarOtros(tamano)"/>
      </P>
      </div>    
  </logic:notPresent>
</form>
